diff --git a/cocos/3d/assets/mesh.ts b/cocos/3d/assets/mesh.ts index 76092dc01c..7215347f09 100644 --- a/cocos/3d/assets/mesh.ts +++ b/cocos/3d/assets/mesh.ts @@ -228,6 +228,18 @@ export class RenderingMesh { } } +export interface IMeshCreateInfo { + /** + * 网格结构。 + */ + struct: IMeshStruct; + + /** + * 网格二进制数据。 + */ + data: Uint8Array; +} + /** * 网格资源。 */ @@ -412,11 +424,23 @@ export class Mesh extends Asset { * 重置此网格的结构和数据。 * @param struct 新的结构。 * @param data 新的数据。 + * @deprecated 将在 V1.0.0 移除,请转用 `this.reset()`。 */ public assign (struct: IMeshStruct, data: Uint8Array) { + this.reset({ + struct, + data, + }); + } + + /** + * 重置此网格。 + * @param info 网格重置选项。 + */ + public reset (info: IMeshCreateInfo) { this.destroyRenderingMesh(); - this._struct = struct; - this._data = data; + this._struct = info.struct; + this._data = info.data; this.loaded = true; this.emit('load'); } @@ -455,7 +479,7 @@ export class Mesh extends Asset { if (!this._initialized && mesh._data) { const struct = JSON.parse(JSON.stringify(mesh._struct)); const data = mesh._data.slice(); - this.assign(struct, data); + this.reset({struct, data}); this.initialize(); return true; } @@ -663,7 +687,10 @@ export class Mesh extends Asset { } // Create mesh. - this.assign(meshStruct, new Uint8Array(bufferBlob.getCombined())); + this.reset({ + struct: meshStruct, + data: new Uint8Array(bufferBlob.getCombined()), + }); this.initialize(); return true; diff --git a/cocos/3d/assets/texture-cube.ts b/cocos/3d/assets/texture-cube.ts index 74b33dc276..4db8741d2c 100644 --- a/cocos/3d/assets/texture-cube.ts +++ b/cocos/3d/assets/texture-cube.ts @@ -73,14 +73,23 @@ export class TextureCube extends TextureBase { this._mipmaps = value; if (this._mipmaps.length > 0) { const imageAsset: ImageAsset = this._mipmaps[0].front; - this.create(imageAsset.width, imageAsset.height, imageAsset.format, this._mipmaps.length); + this.reset({ + width: imageAsset.width, + height: imageAsset.height, + format: imageAsset.format, + mipmapLevel: this._mipmaps.length, + }); this._mipmaps.forEach((mipmap, level) => { _forEachFace(mipmap, (face, faceIndex) => { this._assignImage(face, level, faceIndex); }); }); } else { - this.create(0, 0, undefined, this._mipmaps.length); + this.reset({ + width: 0, + height: 0, + mipmapLevel: this._mipmaps.length, + }); } } diff --git a/cocos/3d/framework/avatar-model-component.ts b/cocos/3d/framework/avatar-model-component.ts index 2e32058738..5c0173bde8 100644 --- a/cocos/3d/framework/avatar-model-component.ts +++ b/cocos/3d/framework/avatar-model-component.ts @@ -372,7 +372,10 @@ export class AvatarModelComponent extends SkinningModelComponent { const meshData = unit.mesh.data.slice(); const newMesh = new Mesh(); - newMesh.assign(unit.mesh.struct, meshData); + newMesh.reset({ + struct: unit.mesh.struct, + data: meshData, + }); dataView = new DataView(meshData.buffer); const struct = unit.mesh.struct; @@ -420,7 +423,11 @@ export class AvatarModelComponent extends SkinningModelComponent { private resizeCombinedTexture () { if (this._combinedTex) { this._combinedTex.destroy(); - this._combinedTex.create(this._combinedTexSize, this._combinedTexSize, PixelFormat.RGBA8888); + this._combinedTex.reset({ + width: this._combinedTexSize, + height: this._combinedTexSize, + format: PixelFormat.RGBA8888, + }); } } } diff --git a/cocos/3d/framework/batched-skinning-model-component.ts b/cocos/3d/framework/batched-skinning-model-component.ts index f338359881..89f5cb69c1 100644 --- a/cocos/3d/framework/batched-skinning-model-component.ts +++ b/cocos/3d/framework/batched-skinning-model-component.ts @@ -357,7 +357,10 @@ export class BatchedSkinningModelComponent extends SkinningModelComponent { } } const newMesh = new Mesh(); - newMesh.assign(newMeshStruct, newMeshData); + newMesh.reset({ + struct: newMeshStruct, + data: newMeshData, + }); const offset = unit.offset; const size = unit.size; @@ -435,7 +438,11 @@ export class BatchedSkinningModelComponent extends SkinningModelComponent { protected createTexture (prop: string) { const tex = new Texture2D(); tex.setFilters(Filter.LINEAR, Filter.LINEAR); - tex.create(this.atlasSize, this.atlasSize, PixelFormat.RGBA8888); + tex.reset({ + width: this.atlasSize, + height: this.atlasSize, + format: PixelFormat.RGBA8888, + }); tex.loaded = true; this._textures[prop] = tex; return tex; @@ -444,7 +451,11 @@ export class BatchedSkinningModelComponent extends SkinningModelComponent { protected resizeAtlases () { for (const prop of Object.keys(this._textures)) { const tex = this._textures[prop]; - tex.create(this.atlasSize, this.atlasSize, PixelFormat.RGBA8888); + tex.reset({ + width: this.atlasSize, + height: this.atlasSize, + format: PixelFormat.RGBA8888, + }); } } } diff --git a/cocos/3d/misc/utils.ts b/cocos/3d/misc/utils.ts index 5e8fdcb069..516528c698 100644 --- a/cocos/3d/misc/utils.ts +++ b/cocos/3d/misc/utils.ts @@ -240,8 +240,13 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: ICreateMe } // Create mesh. - if (!out) { out = new Mesh(); } - out.assign(meshStruct, new Uint8Array(bufferBlob.getCombined())); + if (!out) { + out = new Mesh(); + } + out.reset({ + struct: meshStruct, + data: new Uint8Array(bufferBlob.getCombined()), + }); return out; } diff --git a/cocos/assets/texture-2d.ts b/cocos/assets/texture-2d.ts index 77d24ab98b..4ca7fcb934 100644 --- a/cocos/assets/texture-2d.ts +++ b/cocos/assets/texture-2d.ts @@ -46,12 +46,21 @@ export class Texture2D extends TextureBase { this._mipmaps = value; if (this._mipmaps.length > 0) { const imageAsset: ImageAsset = this._mipmaps[0]; - this.create(imageAsset.width, imageAsset.height, imageAsset.format, this._mipmaps.length); + this.reset({ + width: imageAsset.width, + height: imageAsset.height, + format: imageAsset.format, + mipmapLevel: this._mipmaps.length, + }); this._mipmaps.forEach((mipmap, level) => { this._assignImage(mipmap, level); }); } else { - this.create(0, 0, undefined, this._mipmaps.length); + this.reset({ + width: 0, + height: 0, + mipmapLevel: this._mipmaps.length, + }); } } diff --git a/cocos/assets/texture-base.ts b/cocos/assets/texture-base.ts index 1391f0cf7e..cf3c59b9e9 100644 --- a/cocos/assets/texture-base.ts +++ b/cocos/assets/texture-base.ts @@ -63,6 +63,33 @@ const _regions: GFXBufferTextureCopy[] = [{ }, }]; +/** + * 贴图创建选项。 + */ +export interface ITextureCreateInfo { + /** + * 像素宽度。 + */ + width: number; + + /** + * 像素高度。 + */ + height: number; + + /** + * 像素格式。 + * @default PixelFormat.RGBA8888 + */ + format?: PixelFormat; + + /** + * mipmap 层级。 + * @default 1 + */ + mipmapLevel?: number; +} + /** * 贴图资源基类。它定义了所有贴图共用的概念。 */ @@ -161,19 +188,40 @@ export class TextureBase extends Asset { } /** - * 将当且贴图重置为指定尺寸、像素格式以及指定 mipmap 层级的贴图。重置后,贴图的像素数据将变为未定义。 + * 将当前贴图重置为指定尺寸、像素格式以及指定 mipmap 层级。重置后,贴图的像素数据将变为未定义。 + * mipmap 图像的数据不会自动更新到贴图中,你必须显式调用 `this.uploadData` 来上传贴图数据。 + * @param info 贴图重置选项。 + */ + public reset (info: ITextureCreateInfo) { + if (info.format === undefined) { + info.format = PixelFormat.RGBA8888; + } + if (info.mipmapLevel === undefined) { + info.mipmapLevel = 1; + } + this._potientialWidth = info.width; + this._potientialHeight = info.height; + this._format = info.format; + this._mipmapLevel = info.mipmapLevel; + this._recreateTexture(); + } + + /** + * 将当前贴图重置为指定尺寸、像素格式以及指定 mipmap 层级的贴图。重置后,贴图的像素数据将变为未定义。 * mipmap 图像的数据不会自动更新到贴图中,你必须显式调用 `this.uploadData` 来上传贴图数据。 * @param width 像素宽度。 * @param height 像素高度。 * @param format 像素格式。 * @param mipmapLevel mipmap 层级。 + * @deprecated 将在 V1.0.0 移除,请转用 `this.reset()`。 */ public create (width: number, height: number, format = PixelFormat.RGBA8888, mipmapLevel = 1) { - this._potientialWidth = width; - this._potientialHeight = height; - this._format = format; - this._mipmapLevel = mipmapLevel; - this._recreateTexture(); + this.reset({ + width, + height, + format, + mipmapLevel, + }); } /** diff --git a/cocos/components/animation-component.ts b/cocos/components/animation-component.ts index 8f0392f0b8..836a41979b 100644 --- a/cocos/components/animation-component.ts +++ b/cocos/components/animation-component.ts @@ -247,9 +247,8 @@ export class AnimationComponent extends Component implements IEventTarget { } /** - * @zh - * 获取指定的动画状态。
- * **即将弃用**,请使用 [[getState]]。 + * 获取指定的动画状态。 + * @deprecated 将在 V1.0.0 移除,请转用 `this.getState()`。 */ public getAnimationState (name: string) { return this.getState(name); @@ -295,9 +294,8 @@ export class AnimationComponent extends Component implements IEventTarget { } /** - * @zh - * 添加一个动画剪辑到 `this.clips`中并以此剪辑创建动画状态。
- * **即将弃用**,请使用 [[createState]] + * 添加一个动画剪辑到 `this.clips`中并以此剪辑创建动画状态。 + * @deprecated 将在 V1.0.0 移除,请转用 `this.createState()`。 * @param clip 动画剪辑。 * @param name 动画状态的名称,若未指定,则使用动画剪辑的名称。 * @returns 新创建的动画状态。 @@ -318,7 +316,7 @@ export class AnimationComponent extends Component implements IEventTarget { * 从动画列表中移除指定的动画剪辑,
* 如果依赖于 clip 的 AnimationState 正在播放或者 clip 是 defaultClip 的话,默认是不会删除 clip 的。
* 但是如果 force 参数为 true,则会强制停止该动画,然后移除该动画剪辑和相关的动画。这时候如果 clip 是 defaultClip,defaultClip 将会被重置为 null。
- * **即将弃用**,请使用 [[removeState]] + * @deprecated 将在 V1.0.0 移除,请转用 `this.removeState()`。 * @param {Boolean} [force=false] - If force is true, then will always remove the clip and any animation states based on it. */ public removeClip (clip: AnimationClip, force?: boolean) { diff --git a/cocos/renderer/models/skinning-model.ts b/cocos/renderer/models/skinning-model.ts index ad55477928..15924c2db9 100644 --- a/cocos/renderer/models/skinning-model.ts +++ b/cocos/renderer/models/skinning-model.ts @@ -132,7 +132,11 @@ export class SkinningModel extends Model { if (type !== JointsMediumType.UNIFORM) { const texture = this._jointsMedium.texture = new Texture2D(); - texture.create(width, height, format); + texture.reset({ + width, + height, + format, + }); texture.setFilters(Filter.NEAREST, Filter.NEAREST); texture.setWrapMode(WrapMode.CLAMP_TO_EDGE, WrapMode.CLAMP_TO_EDGE);