add reset() to Mesh and Texture (#4745)

* add reset() to Mesh and Texture

* use tag deprecated

* typo
This commit is contained in:
Leslie Leigh
2019-06-28 16:17:00 +08:00
committed by Weiliang Wang
parent 4e1875ae0c
commit b5623dee6a
9 changed files with 147 additions and 29 deletions
+31 -4
View File
@@ -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;
+11 -2
View File
@@ -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,
});
}
}
+9 -2
View File
@@ -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,
});
}
}
}
@@ -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,
});
}
}
}
+7 -2
View File
@@ -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;
}
+11 -2
View File
@@ -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,
});
}
}
+54 -6
View File
@@ -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,
});
}
/**
+5 -7
View File
@@ -247,9 +247,8 @@ export class AnimationComponent extends Component implements IEventTarget {
}
/**
* @zh
* 获取指定的动画状态。<br>
* **即将弃用**,请使用 [[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`中并以此剪辑创建动画状态。<br>
* **即将弃用**,请使用 [[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 {
* 从动画列表中移除指定的动画剪辑,<br/>
* 如果依赖于 clip 的 AnimationState 正在播放或者 clip 是 defaultClip 的话,默认是不会删除 clip 的。<br/>
* 但是如果 force 参数为 true,则会强制停止该动画,然后移除该动画剪辑和相关的动画。这时候如果 clip 是 defaultClip,defaultClip 将会被重置为 null。<br/>
* **即将弃用**,请使用 [[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) {
+5 -1
View File
@@ -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);