From f2f8da8cbbf617b437da9776f641a3714e3fad63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Fri, 27 Dec 2019 18:50:39 +0800 Subject: [PATCH] Special process for implementation of animation of uniform component (#5980) * Special process for implementation of animation of uniform component * Fix serialization issue --- .../animation/value-proxy-factories/uniform.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cocos/core/animation/value-proxy-factories/uniform.ts b/cocos/core/animation/value-proxy-factories/uniform.ts index 14a3bdb034..096c189683 100644 --- a/cocos/core/animation/value-proxy-factories/uniform.ts +++ b/cocos/core/animation/value-proxy-factories/uniform.ts @@ -6,8 +6,8 @@ import { builtinResMgr } from '../../3d/builtin/init'; import { Material } from '../../assets/material'; import { SpriteFrame } from '../../assets/sprite-frame'; import { TextureBase } from '../../assets/texture-base'; -import { ccclass, property } from '../../data/class-decorator'; -import { GFXBindingType } from '../../gfx/define'; +import { ccclass, property, float } from '../../data/class-decorator'; +import { GFXBindingType, GFXType } from '../../gfx/define'; import { Pass } from '../../renderer/core/pass'; import { type2default } from '../../renderer/core/pass-utils'; import { samplerLib } from '../../renderer/core/sampler-lib'; @@ -21,6 +21,12 @@ export class UniformProxyFactory implements IValueProxyFactory { @property public uniformName: string = ''; + /** + * Use when your target is a single channel of the uniform instead of who uniform. + */ + @float + public channelIndex: number | undefined = undefined; + constructor (uniformName?: string, passIndex?: number) { this.passIndex = passIndex || 0; this.uniformName = uniformName || ''; @@ -34,16 +40,20 @@ export class UniformProxyFactory implements IValueProxyFactory { } const bindingType = Pass.getBindingTypeFromHandle(handle); if (bindingType === GFXBindingType.UNIFORM_BUFFER) { + const realHandle = this.channelIndex === undefined ? handle : pass.getHandle(this.uniformName, this.channelIndex, GFXType.FLOAT); + if (realHandle === undefined) { + throw new Error(`Uniform "${this.uniformName} (in material ${target.name}) has no channel ${this.channelIndex}"`); + } if (isUniformArray(pass, this.uniformName)) { return { set: (value: any) => { - pass.setUniformArray(handle, value); + pass.setUniformArray(realHandle, value); }, }; } else { return { set: (value: any) => { - pass.setUniform(handle, value); + pass.setUniform(realHandle, value); }, }; }