From 2f7f6eb1434deb8d54867ca8fc50b7e908bdff19 Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Thu, 25 Apr 2019 14:35:55 +0800 Subject: [PATCH] update files --- cocos/3d/framework/avatar-model-component.ts | 88 ++++++++++++++++++-- cocos/3d/framework/model-component.ts | 2 +- cocos/renderer/models/skinning-model.ts | 2 +- 3 files changed, 81 insertions(+), 11 deletions(-) diff --git a/cocos/3d/framework/avatar-model-component.ts b/cocos/3d/framework/avatar-model-component.ts index 8240f6a8d9..384977d520 100644 --- a/cocos/3d/framework/avatar-model-component.ts +++ b/cocos/3d/framework/avatar-model-component.ts @@ -22,9 +22,21 @@ THE SOFTWARE. ****************************************************************************/ -import { ccclass, executeInEditMode, executionOrder, menu } from '../../core/data/class-decorator'; +import { Texture2D } from '../../assets'; +import { Filter, PixelFormat } from '../../assets/texture-base'; +import { Rect } from '../../core'; +import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator'; import { GFXDevice } from '../../gfx/device'; +import { Mesh } from '../assets'; import { SkinningModelComponent } from './skinning-model-component'; +import { GFXTextureCopy } from '../../gfx/define'; + +export interface IAvatarUnit { + mesh: Mesh; + region: Rect; + albedoMap: Texture2D | null; + alphaMap: Texture2D | null; +} /** * !#en The Avatar Model Component @@ -36,6 +48,22 @@ import { SkinningModelComponent } from './skinning-model-component'; @menu('Components/AvatarModelComponent') export class AvatarModelComponent extends SkinningModelComponent { + @property + private _combinedTexSize: number = 1024; + + private _combinedTex: Texture2D | null = null; + + private _units: Array = []; + + @property({ visible: false }) + get mesh (): Mesh | null { + return this._mesh; + } + + get parts (): Array { + return this._units; + } + constructor () { super(); } @@ -43,7 +71,9 @@ export class AvatarModelComponent extends SkinningModelComponent { public onLoad () { super.onLoad(); - + this._combinedTex = new Texture2D(); + this._combinedTex.setFilters(Filter.LINEAR, Filter.LINEAR); + this.resizeCombiendTexture(); } public update (dt) { @@ -51,14 +81,54 @@ export class AvatarModelComponent extends SkinningModelComponent { } public onDestroy () { + if (this._combinedTex) { + this._combinedTex.destroy(); + this._combinedTex = null; + } } -} -function _getGlobalDevice (): GFXDevice | null { - // @ts-ignore - if (cc.director && cc.director.root) { - return cc.director.root.device; - } else { - return null; + public combine () { + + const texImages: TexImageSource[] = []; + const texImageRegions: GFXTextureCopy[] = []; + const texBuffers: ArrayBuffer[] = []; + const texBufferRegions: GFXTextureCopy[] = []; + + for (const unit of this._units) { + if (unit) { + const isValid = (unit.region.x > 0 && unit.region.y > 0) && + (unit.region.width > 0 && unit.region.height > 0) && + (unit.region.x + unit.region.width) <= this._combinedTexSize && + (unit.region.y + unit.region.height) <= this._combinedTexSize; + + if (isValid && unit.albedoMap && unit.albedoMap.image && unit.albedoMap.image.data) { + + const region = new GFXTextureCopy(); + + const data = unit.albedoMap.image.data; + if (data instanceof HTMLCanvasElement || data instanceof HTMLImageElement) { + texImages.push(data); + texImageRegions.push(region); + } else { + texBuffers.push(data.buffer); + texBufferRegions.push(region); + } + } + } + } + + const gfxTex = this._combinedTex!.getGFXTexture(); + const device: GFXDevice = cc.director.root.device; + for (const buff of texBuffers) { + // device.copyBuffersToTexture(texBuffers, gfxTex!, ); + } + // device.copyTexImagesToTexture(); + } + + private resizeCombiendTexture () { + if (this._combinedTex) { + this._combinedTex.destroy(); + this._combinedTex.create(this._combinedTexSize, this._combinedTexSize, PixelFormat.RGBA8888); + } } } diff --git a/cocos/3d/framework/model-component.ts b/cocos/3d/framework/model-component.ts index a35585874b..647ecff4bd 100644 --- a/cocos/3d/framework/model-component.ts +++ b/cocos/3d/framework/model-component.ts @@ -152,7 +152,7 @@ export class ModelComponent extends RenderableComponent { protected _model: Model | null = null; @property - private _mesh: Mesh | null = null; + protected _mesh: Mesh | null = null; @property private _shadowCastingMode = ModelShadowCastingMode.Off; diff --git a/cocos/renderer/models/skinning-model.ts b/cocos/renderer/models/skinning-model.ts index bfd49759af..76e6116b3c 100644 --- a/cocos/renderer/models/skinning-model.ts +++ b/cocos/renderer/models/skinning-model.ts @@ -173,7 +173,7 @@ export function selectStorageKind (device: GFXDevice): JointStorageKind { } else if (device.gfxAPI === GFXAPI.WEBGL2) { return JointStorageKind.uniform; // BUG Now } else if (device.hasFeature(GFXFeature.TEXTURE_FLOAT)) { - return JointStorageKind.textureRGBA8; + return JointStorageKind.textureRGBA32F; } else { return JointStorageKind.textureRGBA8; }