Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.8.2 merge v3.8.1 #16223

Merged
merged 29 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
442f740
macos 10.x -> 11+ api change (#16153)
hana-alice Aug 31, 2023
2b27581
post-final pass keep alpha channel (#16149)
troublemaker52025 Aug 31, 2023
4d21393
fix update widget occur error (#16139)
arsen2010 Aug 31, 2023
2b18d25
Add openharmony CI support (#16151)
dumganhar Aug 31, 2023
e2e4ceb
change shader strip (#16167)
star-e Sep 1, 2023
ba70fe1
fix bind cont EventData * bind, modify the address as a reference. (#…
Canvasfull Sep 1, 2023
70b7875
don`t destroy sub com when mask destroy (#16162)
LinYunMo Sep 1, 2023
692d3dc
fix debug view with custom pipeline and revert LDR fog to HDR (#16163)
jk20012001 Sep 1, 2023
eaeab8b
delete rangeddir / point light custom template form components.js (#1…
troublemaker52025 Sep 1, 2023
48a5791
fix format validation. (#16177)
bluesky013 Sep 4, 2023
cdca5b0
Fix orientation does not work normaly on huawei-agc platform (#16180)
bofeng-song Sep 4, 2023
dc933d3
add experimental box2d wasm i18n (#16134)
lealzhan Sep 5, 2023
fbbda83
update gitignore (#16187)
PPpro Sep 5, 2023
a45535e
fix getHDRInputName undefine with cyberpunk (#16192)
troublemaker52025 Sep 6, 2023
51dc67e
Fix an issue where node_modules was not removed when clearing the cac…
VisualSJ Sep 6, 2023
d198a19
[fix] box2d wasm rigid-body destroy() should destroy related shapes a…
lealzhan Sep 6, 2023
fc986c9
fix webgpu crash with normalize zero vector (#16195)
jk20012001 Sep 6, 2023
50c2d70
update native/external-config: [fix] cct scaling causes trigger event…
lealzhan Sep 6, 2023
c6d1782
update world bound when update models (#16189)
moshuying Sep 6, 2023
23a44ed
Modify camera component ortho height's min value to 0 (#16181)
shrinktofit Sep 6, 2023
0b65ab3
add CULL_MESHOPT constant (#16194)
PPpro Sep 7, 2023
2cb1652
Add workflow_dispatch for oh sdk & vulkan sdk (#16204)
dumganhar Sep 7, 2023
7f7de0a
Add dirty flag to edit box (#16209)
LinYunMo Sep 7, 2023
4dbd525
fix sphere 2nd uv (#16210)
jk20012001 Sep 7, 2023
b57d5ab
Resolved error when getting length for Record type (#16213)
troublemaker52025 Sep 8, 2023
3822786
Fix SDL-related issues (#16212)
qiuguohua Sep 8, 2023
b46cba6
Fix/meshopt (#16200)
yiwenxue Sep 8, 2023
4c7d2ce
Fixed the problem of new pipeline don't clear reporting an error (#16…
GengineJS Sep 8, 2023
5545986
Merge branch 'v3.8.1' into v3.8.2-merge-v3.8.1
minggo Sep 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/lib
lib/
.turbo/
/bin
/web.config
.idea
Expand Down
6 changes: 6 additions & 0 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,12 @@
"type": "boolean",
"value": false,
"internal": true
},
"CULL_MESHOPT": {
"comment": "An internal constant to indicate whether we cull the meshopt wasm module and asm.js module.",
"type": "boolean",
"value": true,
"internal": true
}
},

Expand Down
2 changes: 0 additions & 2 deletions cocos/2d/components/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,9 @@ export class Mask extends Component {

protected _removeMaskNode (): void {
if (this._sprite) {
this._sprite.destroy();
this._sprite = null;
}
if (this._graphics) {
this._graphics.destroy();
this._graphics = null;
}
}
Expand Down
160 changes: 153 additions & 7 deletions cocos/3d/assets/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import { Asset } from '../../asset/assets/asset';
import { IDynamicGeometry } from '../../primitive/define';
import { BufferBlob } from '../misc/buffer-blob';
import { Skeleton } from './skeleton';
import { geometry, cclegacy, sys, warnID, Mat4, Quat, Vec3, assertIsTrue, murmurhash2_32_gc, errorID } from '../../core';
import { geometry, cclegacy, sys, warnID, Mat4, Quat, Vec3, assertIsTrue, murmurhash2_32_gc, errorID, halfToFloat } from '../../core';
import { RenderingSubMesh } from '../../asset/assets';
import {
Attribute, Device, Buffer, BufferInfo, AttributeName, BufferUsageBit, Feature, Format,
FormatInfos, FormatType, MemoryUsageBit, PrimitiveMode, getTypedArrayConstructor, DrawInfo, FormatInfo, deviceManager,
FormatInfos, FormatType, MemoryUsageBit, PrimitiveMode, getTypedArrayConstructor, DrawInfo, FormatInfo, deviceManager, FormatFeatureBit,
} from '../../gfx';
import { Morph } from './morph';
import { MorphRendering, createMorphRendering } from './morph-rendering';
Expand Down Expand Up @@ -409,6 +409,11 @@ export class Mesh extends Asset {
if (this.struct.encoded) { // decode mesh data
info = decodeMesh(info);
}
if (this.struct.quantized
&& !(deviceManager.gfxDevice.getFormatFeatures(Format.RGB16F) & FormatFeatureBit.VERTEX_ATTRIBUTE)) {
// dequantize mesh data
info = dequantizeMesh(info);
}

this._struct = info.struct;
this._data = info.data;
Expand Down Expand Up @@ -1507,11 +1512,6 @@ export function decodeMesh (mesh: Mesh.ICreateInfo): Mesh.ICreateInfo {
return mesh;
}

// decode the mesh
if (!MeshoptDecoder.supported) {
return mesh;
}

const res_checker = (res: number): void => {
if (res < 0) {
errorID(14204, res);
Expand Down Expand Up @@ -1581,4 +1581,150 @@ export function inflateMesh (mesh: Mesh.ICreateInfo): Mesh.ICreateInfo {
return mesh;
}

export function dequantizeMesh (mesh: Mesh.ICreateInfo): Mesh.ICreateInfo {
const struct = JSON.parse(JSON.stringify(mesh.struct)) as Mesh.IStruct;

const bufferBlob = new BufferBlob();
bufferBlob.setNextAlignment(0);

function transformVertex (
reader: ((offset: number) => number),
writer: ((offset: number, value: number) => void),
count: number,
components: number,
componentSize: number,
readerStride: number,
writerStride: number,
): void {
for (let i = 0; i < count; i++) {
for (let j = 0; j < components; j++) {
const inputOffset = readerStride * i + componentSize * j;
const outputOffset = writerStride * i + componentSize * j;
writer(outputOffset, reader(inputOffset));
}
}
}

function dequantizeHalf (
reader: ((offset: number) => number),
writer: ((offset: number, value: number) => void),
count: number,
components: number,
readerStride: number,
writerStride: number,
): void {
for (let i = 0; i < count; i++) {
for (let j = 0; j < components; j++) {
const inputOffset = readerStride * i + 2 * j;
const outputOffset = writerStride * i + 4 * j;
const value = halfToFloat(reader(inputOffset));
writer(outputOffset, value);
}
}
}

for (let i = 0; i < struct.vertexBundles.length; ++i) {
const bundle = struct.vertexBundles[i];
const view = bundle.view;
const attributes = bundle.attributes;
const oldAttributes = mesh.struct.vertexBundles[i].attributes;
const strides: number[] = [];
const dequantizes: boolean[] = [];
const readers: ((offset: number) => number)[] = [];
for (let j = 0; j < attributes.length; ++j) {
const attr = attributes[j];
const inputView = new DataView(mesh.data.buffer, view.offset + getOffset(oldAttributes, j));
const reader = getReader(inputView, attr.format);
let dequantize = true;
switch (attr.format) {
case Format.R16F:
attr.format = Format.R32F;
break;
case Format.RG16F:
attr.format = Format.RG32F;
break;
case Format.RGB16F:
attr.format = Format.RGB32F;
break;
case Format.RGBA16F:
attr.format = Format.RGBA32F;
break;
default:
dequantize = false;
break;
}
strides.push(FormatInfos[attr.format].size);
dequantizes.push(dequantize);
readers.push(reader!);
}
const netStride = strides.reduce((acc, cur) => acc + cur, 0);
const newBuffer = new Uint8Array(netStride * view.count);
for (let j = 0; j < attributes.length; ++j) {
const attribute = attributes[j];
const reader = readers[j];
const outputView = new DataView(newBuffer.buffer, getOffset(attributes, j));
const writer = getWriter(outputView, attribute.format)!;
const dequantize = dequantizes[j];
const formatInfo = FormatInfos[attribute.format];
if (dequantize) {
dequantizeHalf(
reader,
writer,
view.count,
formatInfo.count,
view.stride,
netStride,
);
} else {
transformVertex(
reader,
writer,
view.count,
formatInfo.count,
formatInfo.size / formatInfo.count,
view.stride,
netStride,
);
}
}

bufferBlob.setNextAlignment(netStride);
const newView: Mesh.IBufferView = {
offset: bufferBlob.getLength(),
length: newBuffer.byteLength,
count: view.count,
stride: netStride,
};
bundle.view = newView;
bufferBlob.addBuffer(newBuffer);
}

// dump index buffer
for (const primitive of struct.primitives) {
if (primitive.indexView === undefined) {
continue;
}
const view = primitive.indexView;
const buffer = new Uint8Array(mesh.data.buffer, view.offset, view.length);
bufferBlob.setNextAlignment(view.stride);
const newView: Mesh.IBufferView = {
offset: bufferBlob.getLength(),
length: buffer.byteLength,
count: view.count,
stride: view.stride,
};
primitive.indexView = newView;
bufferBlob.addBuffer(buffer);
}

const data = new Uint8Array(bufferBlob.getCombined());

struct.quantized = false;

return {
struct,
data,
};
}

// function get
1 change: 1 addition & 0 deletions cocos/3d/framework/mesh-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ export class MeshRenderer extends ModelRenderer {
if (this._mesh) {
const meshStruct = this._mesh.struct;
this._model.createBoundingShape(meshStruct.minPosition, meshStruct.maxPosition);
this._model.updateWorldBound();
}
// Initialize lighting map before model initializing
// because the lighting map will influence the model's shader
Expand Down
6 changes: 4 additions & 2 deletions cocos/3d/misc/mesh-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { WASM_SUPPORT_MODE } from 'internal:constants';
import { CULL_MESHOPT, WASM_SUPPORT_MODE } from 'internal:constants';
import { ensureWasmModuleReady, instantiateWasm } from 'pal/wasm';

import { sys, logID } from '../../core';
Expand Down Expand Up @@ -90,4 +90,6 @@ export function InitDecoder (): Promise<void> {
}));
}

game.onPostInfrastructureInitDelegate.add(InitDecoder);
if (!CULL_MESHOPT) {
game.onPostInfrastructureInitDelegate.add(InitDecoder);
}
6 changes: 3 additions & 3 deletions cocos/misc/camera-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export class Camera extends Component {
*/
@type(FOVAxis)
@displayOrder(7)
@visible(function (this: Camera): boolean {
@visible(function visible (this: Camera): boolean {
return this._projection === ProjectionType.PERSPECTIVE;
})
@tooltip('i18n:camera.fov_axis')
Expand Down Expand Up @@ -354,10 +354,10 @@ export class Camera extends Component {
* @zh 正交模式下的相机视角高度。
*/
@displayOrder(9)
@visible(function (this: Camera): boolean {
@visible(function visible (this: Camera): boolean {
return this._projection === ProjectionType.ORTHO;
})
@rangeMin(1)
@rangeMin(1e-6)
@tooltip('i18n:camera.ortho_height')
get orthoHeight (): number {
return this._orthoHeight;
Expand Down
3 changes: 2 additions & 1 deletion cocos/physics-2d/box2d-wasm/instantiated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const B2 = {} as any;

export function getImplPtr (wasmObject: any): number {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return (wasmObject).$$.ptr;
if (!wasmObject) return 0;
return (wasmObject).$$.ptr as number;
}

/**
Expand Down
8 changes: 5 additions & 3 deletions cocos/physics-2d/box2d-wasm/joints/joint-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
THE SOFTWARE.
*/

import { B2, addImplPtrReference, addImplPtrReferenceWASM, getImplPtr } from '../instantiated';
import { B2, addImplPtrReference, addImplPtrReferenceWASM, getImplPtr, removeImplPtrReference, removeImplPtrReferenceWASM } from '../instantiated';
import { IJoint2D } from '../../spec/i-physics-joint';
import { Joint2D, PhysicsSystem2D, RigidBody2D } from '../../framework';
import { B2PhysicsWorld } from '../physics-world';
Expand Down Expand Up @@ -54,7 +54,7 @@ export class B2Joint implements IJoint2D {
}

onDisable (): void {
PhysicsSystem2D.instance._callAfterStep(this, this._destroy);
PhysicsSystem2D.instance._callAfterStep(this, this.destroy);
}

// need init after body and connected body init
Expand Down Expand Up @@ -106,9 +106,11 @@ export class B2Joint implements IJoint2D {
this._inited = true;
}

_destroy (): void {
destroy (): void {
if (!this._inited) return;

removeImplPtrReference(getImplPtr(this._b2joint));
removeImplPtrReferenceWASM(getImplPtr(this._b2joint));
(PhysicsSystem2D.instance.physicsWorld as B2PhysicsWorld).impl.DestroyJoint(this._b2joint!);

this._b2joint = null;
Expand Down
2 changes: 1 addition & 1 deletion cocos/physics-2d/box2d-wasm/joints/mouse-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class B2MouseJoint extends B2Joint implements IMouseJoint {
}

onTouchEnd (event: Touch): void {
this._destroy();
this.destroy();
this._isTouched = false;
}

Expand Down
29 changes: 27 additions & 2 deletions cocos/physics-2d/box2d-wasm/rigid-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
THE SOFTWARE.
*/

import { B2 } from './instantiated';
import { B2, getTSObjectFromWASMObject, getTSObjectFromWASMObjectPtr } from './instantiated';
import { IRigidBody2D } from '../spec/i-rigid-body';
import { RigidBody2D } from '../framework/components/rigid-body-2d';
import { PhysicsSystem2D } from '../framework/physics-system';
Expand All @@ -31,8 +31,10 @@ import { Vec2, toRadian, Vec3, Quat, IVec2Like, toDegree, TWO_PI, HALF_PI } from
import { PHYSICS_2D_PTM_RATIO, ERigidBody2DType } from '../framework/physics-types';

import { Node } from '../../scene-graph/node';
import { Collider2D } from '../framework';
import { Collider2D, Joint2D } from '../framework';
import { NodeEventType } from '../../scene-graph/node-event';
import { B2Shape2D } from './shapes/shape-2d';
import { B2Joint } from './joints/joint-2d';

const tempVec3 = new Vec3();
const tempVec2_1 = { x: 0, y: 0 };//new B2.Vec2(0, 0);
Expand Down Expand Up @@ -114,6 +116,29 @@ export class B2RigidBody2D implements IRigidBody2D {
_destroy (): void {
if (!this._inited) return;

//collect all fixtures attached to this rigid body and process them
const fixtureList = this.impl?.GetFixtureList();
if (fixtureList) {
let shapeTSObj = getTSObjectFromWASMObject<B2Shape2D>(fixtureList);
while (shapeTSObj && shapeTSObj.impl) {
shapeTSObj.destroy();
const nextFixture = fixtureList.GetNext();
shapeTSObj = getTSObjectFromWASMObject<B2Shape2D>(nextFixture);
}
}

//collect all joints attached to this rigid body and process them
const jointListPtr = this.impl?.GetJointList();
if (jointListPtr) {
let jointWASMPtr = B2.JointEdgeGetJoint(jointListPtr) as number;
let jointTSObj = getTSObjectFromWASMObjectPtr<B2Joint>(jointWASMPtr);
while (jointTSObj) {
jointTSObj.destroy();
jointWASMPtr = B2.JointEdgeGetNext(jointListPtr) as number;
jointTSObj = getTSObjectFromWASMObjectPtr<B2Joint>(jointWASMPtr);
}
}

(PhysicsSystem2D.instance.physicsWorld as B2PhysicsWorld).removeBody(this);

this._inited = false;
Expand Down
6 changes: 3 additions & 3 deletions cocos/physics-2d/box2d-wasm/shapes/shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class B2Shape2D implements IBaseShape {
}

onDisable (): void {
PhysicsSystem2D.instance._callAfterStep(this, this._destroy);
PhysicsSystem2D.instance._callAfterStep(this, this.destroy);
}

start (): void {
Expand All @@ -92,7 +92,7 @@ export class B2Shape2D implements IBaseShape {
}

apply (): void {
this._destroy();
this.destroy();
if (this.collider.enabledInHierarchy) {
this._init();
}
Expand Down Expand Up @@ -200,7 +200,7 @@ export class B2Shape2D implements IBaseShape {
this._inited = true;
}

_destroy (): void {
destroy (): void {
if (!this._inited) return;

const fixtures = this._fixtures;
Expand Down
Loading