From 75753bbddc2b7da2e6cdfb977fc0b8b8e98d634e Mon Sep 17 00:00:00 2001 From: moshuying <1460083332@qq.com> Date: Mon, 31 Jul 2023 11:54:45 +0800 Subject: [PATCH 1/5] make allowDataAccess is only available at runtime. --- cocos/3d/assets/mesh.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos/3d/assets/mesh.ts b/cocos/3d/assets/mesh.ts index 39b823bb07a..05caaefb015 100644 --- a/cocos/3d/assets/mesh.ts +++ b/cocos/3d/assets/mesh.ts @@ -35,6 +35,7 @@ import { } from '../../gfx'; import { Morph } from './morph'; import { MorphRendering, createMorphRendering } from './morph-rendering'; +import { EDITOR } from 'internal:constants'; function getIndexStrideCtor (stride: number): Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor { switch (stride) { @@ -493,7 +494,7 @@ export class Mesh extends Asset { } this._isMeshDataUploaded = true; - if (!this._allowDataAccess) { + if (!this._allowDataAccess && !EDITOR) { this.releaseData(); } } @@ -1304,7 +1305,7 @@ export class Mesh extends Asset { */ public set allowDataAccess (allowDataAccess: boolean) { this._allowDataAccess = allowDataAccess; - if (this._isMeshDataUploaded && !this._allowDataAccess) { + if (this._isMeshDataUploaded && !this._allowDataAccess && !EDITOR) { this.releaseData(); } } From 8b7d00f0c04a33deea4dba9f5374b8d7bdedc961 Mon Sep 17 00:00:00 2001 From: moshuying <1460083332@qq.com> Date: Mon, 31 Jul 2023 13:42:07 +0800 Subject: [PATCH 2/5] add native code --- native/cocos/3d/assets/Mesh.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/native/cocos/3d/assets/Mesh.cpp b/native/cocos/3d/assets/Mesh.cpp index 588247e8d78..753de135aaa 100644 --- a/native/cocos/3d/assets/Mesh.cpp +++ b/native/cocos/3d/assets/Mesh.cpp @@ -440,7 +440,9 @@ void Mesh::initialize() { _isMeshDataUploaded = true; if (!_allowDataAccess) { +#if !CC_EDITOR releaseData(); +#endif } } } @@ -1261,7 +1263,9 @@ void Mesh::initDefault(const ccstd::optional &uuid) { void Mesh::setAllowDataAccess(bool allowDataAccess) { _allowDataAccess = allowDataAccess; if (_isMeshDataUploaded && !_allowDataAccess) { +#if !CC_EDITOR releaseData(); +#endif } } From 498d1c9841c03769b86dfe846c86460d7665e7e2 Mon Sep 17 00:00:00 2001 From: moshuying <1460083332@qq.com> Date: Mon, 31 Jul 2023 13:45:12 +0800 Subject: [PATCH 3/5] code update --- native/cocos/3d/assets/Mesh.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/cocos/3d/assets/Mesh.cpp b/native/cocos/3d/assets/Mesh.cpp index 753de135aaa..e0b2034f89c 100644 --- a/native/cocos/3d/assets/Mesh.cpp +++ b/native/cocos/3d/assets/Mesh.cpp @@ -439,11 +439,11 @@ void Mesh::initialize() { } _isMeshDataUploaded = true; - if (!_allowDataAccess) { #if !CC_EDITOR + if (!_allowDataAccess) { releaseData(); -#endif } +#endif } } @@ -1262,11 +1262,11 @@ void Mesh::initDefault(const ccstd::optional &uuid) { void Mesh::setAllowDataAccess(bool allowDataAccess) { _allowDataAccess = allowDataAccess; - if (_isMeshDataUploaded && !_allowDataAccess) { #if !CC_EDITOR + if (_isMeshDataUploaded && !_allowDataAccess) { releaseData(); -#endif } +#endif } void Mesh::releaseData() { From bacafcc3ef27ba30787ab8fe003d5d41e44119f5 Mon Sep 17 00:00:00 2001 From: moshuying <1460083332@qq.com> Date: Mon, 31 Jul 2023 18:14:40 +0800 Subject: [PATCH 4/5] fix ts import order --- cocos/3d/assets/mesh.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/3d/assets/mesh.ts b/cocos/3d/assets/mesh.ts index 05caaefb015..49ab9815771 100644 --- a/cocos/3d/assets/mesh.ts +++ b/cocos/3d/assets/mesh.ts @@ -23,6 +23,7 @@ */ import { ccclass, serializable } from 'cc.decorator'; +import { EDITOR } from 'internal:constants'; import { Asset } from '../../asset/assets/asset'; import { IDynamicGeometry } from '../../primitive/define'; import { BufferBlob } from '../misc/buffer-blob'; @@ -35,7 +36,6 @@ import { } from '../../gfx'; import { Morph } from './morph'; import { MorphRendering, createMorphRendering } from './morph-rendering'; -import { EDITOR } from 'internal:constants'; function getIndexStrideCtor (stride: number): Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor { switch (stride) { @@ -320,9 +320,9 @@ export class Mesh extends Asset { @serializable private _struct: Mesh.IStruct = { - vertexBundles: [], - primitives: [], - }; + vertexBundles: [], + primitives: [], + }; @serializable private _hash = 0; From 3411dddb87445d77682f5667863208ecddc95f48 Mon Sep 17 00:00:00 2001 From: moshuying <1460083332@qq.com> Date: Wed, 2 Aug 2023 14:56:05 +0800 Subject: [PATCH 5/5] fix eslint error --- cocos/3d/assets/mesh.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos/3d/assets/mesh.ts b/cocos/3d/assets/mesh.ts index 49ab9815771..0ca33d88c63 100644 --- a/cocos/3d/assets/mesh.ts +++ b/cocos/3d/assets/mesh.ts @@ -320,9 +320,9 @@ export class Mesh extends Asset { @serializable private _struct: Mesh.IStruct = { - vertexBundles: [], - primitives: [], - }; + vertexBundles: [], + primitives: [], + }; @serializable private _hash = 0;