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

make allowDataAccess is only available at runtime. #15835

Merged
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
5 changes: 3 additions & 2 deletions cocos/3d/assets/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -462,9 +463,9 @@

ib = new (getIndexStrideCtor(idxView.stride))(buffer, idxView.offset, idxView.count);
if (idxView.stride !== dstStride) {
ib = getIndexStrideCtor(dstStride).from(ib);

Check failure on line 466 in cocos/3d/assets/mesh.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Iterable<number>`
}
indexBuffer.update(ib);

Check failure on line 468 in cocos/3d/assets/mesh.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Readonly<BufferSource>`
}

const vbReference = prim.vertexBundelIndices.map((idx) => vertexBuffers[idx]);
Expand Down Expand Up @@ -493,7 +494,7 @@
}

this._isMeshDataUploaded = true;
if (!this._allowDataAccess) {
if (!this._allowDataAccess && !EDITOR) {
this.releaseData();
}
}
Expand Down Expand Up @@ -751,7 +752,7 @@
for (let i = 0; i < struct.vertexBundles.length; i++) {
const vtxBdl = struct.vertexBundles[i];
for (let j = 0; j < vtxBdl.attributes.length; j++) {
if (vtxBdl.attributes[j].name === AttributeName.ATTR_POSITION || vtxBdl.attributes[j].name === AttributeName.ATTR_NORMAL) {

Check failure on line 755 in cocos/3d/assets/mesh.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type

Check failure on line 755 in cocos/3d/assets/mesh.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type
const { format } = vtxBdl.attributes[j];

const inputView = new DataView(
Expand Down Expand Up @@ -851,7 +852,7 @@
for (let v = 0; v < dstBundle.view.count; ++v) {
dstAttrView = dstVBView.subarray(dstVBOffset, dstVBOffset + attrSize);
vbView.set(dstAttrView, srcVBOffset);
if ((attr.name === AttributeName.ATTR_POSITION || attr.name === AttributeName.ATTR_NORMAL) && worldMatrix) {

Check failure on line 855 in cocos/3d/assets/mesh.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type

Check failure on line 855 in cocos/3d/assets/mesh.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type
const f32_temp = new Float32Array(vbView.buffer, srcVBOffset, 3);
vec3_temp.set(f32_temp[0], f32_temp[1], f32_temp[2]);
switch (attr.name) {
Expand Down Expand Up @@ -1257,7 +1258,7 @@
const primitive = this._struct.primitives[primitiveIndex];
for (const vertexBundleIndex of primitive.vertexBundelIndices) {
const vertexBundle = this._struct.vertexBundles[vertexBundleIndex];
const iAttribute = vertexBundle.attributes.findIndex((a) => a.name === attributeName);

Check failure on line 1261 in cocos/3d/assets/mesh.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type
if (iAttribute < 0) {
continue;
}
Expand Down Expand Up @@ -1304,7 +1305,7 @@
*/
public set allowDataAccess (allowDataAccess: boolean) {
this._allowDataAccess = allowDataAccess;
if (this._isMeshDataUploaded && !this._allowDataAccess) {
if (this._isMeshDataUploaded && !this._allowDataAccess && !EDITOR) {
this.releaseData();
}
}
Expand Down
4 changes: 4 additions & 0 deletions native/cocos/3d/assets/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,11 @@ void Mesh::initialize() {
}

_isMeshDataUploaded = true;
#if !CC_EDITOR
if (!_allowDataAccess) {
releaseData();
}
#endif
}
}

Expand Down Expand Up @@ -1260,9 +1262,11 @@ void Mesh::initDefault(const ccstd::optional<ccstd::string> &uuid) {

void Mesh::setAllowDataAccess(bool allowDataAccess) {
_allowDataAccess = allowDataAccess;
#if !CC_EDITOR
if (_isMeshDataUploaded && !_allowDataAccess) {
releaseData();
}
#endif
}

void Mesh::releaseData() {
Expand Down
Loading