Special process for implementation of animation of uniform component (#5980)

* Special process for implementation of animation of uniform component

* Fix serialization issue
This commit is contained in:
Leslie Leigh (李的序)
2019-12-27 18:50:39 +08:00
committed by pandamicro
parent eaf1e84870
commit f2f8da8cbb
@@ -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);
},
};
}