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 physics debug draw #16208

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 0 additions & 31 deletions .github/workflows/generate-android-ndk-cache.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/native-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
with:
ndk-version: r21e
add-to-path: false
local-cache: true
- name: Generate decorators
run: |
cd native
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/native-compile-platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ jobs:
with:
ndk-version: r21e
add-to-path: false
local-cache: true
- uses: actions/setup-java@v3
id: setup-jdk
with:
Expand Down Expand Up @@ -145,7 +144,6 @@ jobs:
with:
ndk-version: r21e
add-to-path: false
local-cache: true
- uses: actions/setup-java@v3
id: setup-jdk
with:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/native-linter-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
with:
ndk-version: r21e
add-to-path: false
local-cache: true
- name: Get changed files
uses: PatriceJiang/paths-filter@master
id: listchanged
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
lib/
.turbo/
/lib
/bin
/web.config
.idea
Expand Down
6 changes: 0 additions & 6 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,12 +678,6 @@
"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: 2 additions & 0 deletions cocos/2d/components/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,11 @@ 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: 7 additions & 153 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, halfToFloat } from '../../core';
import { geometry, cclegacy, sys, warnID, Mat4, Quat, Vec3, assertIsTrue, murmurhash2_32_gc, errorID } from '../../core';
import { RenderingSubMesh } from '../../asset/assets';
import {
Attribute, Device, Buffer, BufferInfo, AttributeName, BufferUsageBit, Feature, Format,
FormatInfos, FormatType, MemoryUsageBit, PrimitiveMode, getTypedArrayConstructor, DrawInfo, FormatInfo, deviceManager, FormatFeatureBit,
FormatInfos, FormatType, MemoryUsageBit, PrimitiveMode, getTypedArrayConstructor, DrawInfo, FormatInfo, deviceManager,
} from '../../gfx';
import { Morph } from './morph';
import { MorphRendering, createMorphRendering } from './morph-rendering';
Expand Down Expand Up @@ -409,11 +409,6 @@ 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 @@ -1512,6 +1507,11 @@ 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,150 +1581,4 @@ 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: 0 additions & 1 deletion cocos/3d/framework/mesh-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,6 @@ 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: 2 additions & 4 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 { CULL_MESHOPT, WASM_SUPPORT_MODE } from 'internal:constants';
import { WASM_SUPPORT_MODE } from 'internal:constants';
import { ensureWasmModuleReady, instantiateWasm } from 'pal/wasm';

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

if (!CULL_MESHOPT) {
game.onPostInfrastructureInitDelegate.add(InitDecoder);
}
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 visible (this: Camera): boolean {
@visible(function (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 visible (this: Camera): boolean {
@visible(function (this: Camera): boolean {
return this._projection === ProjectionType.ORTHO;
})
@rangeMin(1e-6)
@rangeMin(1)
@tooltip('i18n:camera.ortho_height')
get orthoHeight (): number {
return this._orthoHeight;
Expand Down
3 changes: 1 addition & 2 deletions cocos/physics-2d/box2d-wasm/instantiated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export const B2 = {} as any;

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

/**
Expand Down
8 changes: 3 additions & 5 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, removeImplPtrReference, removeImplPtrReferenceWASM } from '../instantiated';
import { B2, addImplPtrReference, addImplPtrReferenceWASM, getImplPtr } 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,11 +106,9 @@ 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
Loading
Loading