From 518c2ad3a411ae32c12423f75954ee02df2d89c7 Mon Sep 17 00:00:00 2001 From: Leslie Leigh Date: Wed, 27 Feb 2019 15:23:30 +0800 Subject: [PATCH] fix animation (#3925) --- cocos/3d/framework/renderable-component.ts | 2 +- cocos/3d/framework/skinning-model-component.ts | 15 ++++++++++----- cocos/pipeline/cc-binding.ts | 7 +++++++ cocos/renderer/models/model-uniforms.ts | 5 +++-- cocos/renderer/models/skinning-model.ts | 4 ++-- 5 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 cocos/pipeline/cc-binding.ts diff --git a/cocos/3d/framework/renderable-component.ts b/cocos/3d/framework/renderable-component.ts index a848173b3d..b82e243fc1 100644 --- a/cocos/3d/framework/renderable-component.ts +++ b/cocos/3d/framework/renderable-component.ts @@ -7,7 +7,7 @@ const { ccclass, property } = _decorator; @ccclass('cc.RenderableComponent') export class RenderableComponent extends Component { @property({ type: [Material] }) - private _materials: Array = []; + protected _materials: Array = []; constructor () { super(); diff --git a/cocos/3d/framework/skinning-model-component.ts b/cocos/3d/framework/skinning-model-component.ts index 70ce756dee..50d5a12183 100644 --- a/cocos/3d/framework/skinning-model-component.ts +++ b/cocos/3d/framework/skinning-model-component.ts @@ -27,7 +27,7 @@ import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator'; import { mat4 } from '../../core/vmath'; import { GFXDevice, GFXFeature } from '../../gfx/device'; -import { SkinningModel, __FORCE_USE_UNIFORM_STORAGE__ } from '../../renderer/models/skinning-model'; +import { __FORCE_USE_UNIFORM_STORAGE__, SkinningModel } from '../../renderer/models/skinning-model'; import { Node } from '../../scene-graph/node'; import { Material } from '../assets/material'; import Skeleton from '../assets/skeleton'; @@ -86,6 +86,11 @@ export default class SkinningModelComponent extends ModelComponent { public onLoad () { super.onLoad(); + this._materials.forEach((material, index) => { + if (material) { + this._onMaterialModified(index, material); + } + }); this._resetSkinningTarget(); } @@ -126,16 +131,16 @@ export default class SkinningModelComponent extends ModelComponent { skinningModel.commitJointMatrices(); } - protected _getModelConstructor () { - return SkinningModel; - } - public _updateModelParams () { // Should bind skeleton before super create pso this._bindSkeleton(); super._updateModelParams(); } + protected _getModelConstructor () { + return SkinningModel; + } + protected _onMaterialModified (index: number, material: Material) { super._onMaterialModified(index, material); diff --git a/cocos/pipeline/cc-binding.ts b/cocos/pipeline/cc-binding.ts new file mode 100644 index 0000000000..f674d73a23 --- /dev/null +++ b/cocos/pipeline/cc-binding.ts @@ -0,0 +1,7 @@ + +const MAX_BINDING = 24; + +export enum UBOBinding { + CC_SKINNING = MAX_BINDING - 6, + CC_JOINTS_TEXTURE = MAX_BINDING - 7, +} diff --git a/cocos/renderer/models/model-uniforms.ts b/cocos/renderer/models/model-uniforms.ts index 0c24d96ff1..da5a0b43d3 100644 --- a/cocos/renderer/models/model-uniforms.ts +++ b/cocos/renderer/models/model-uniforms.ts @@ -1,5 +1,6 @@ import { GFXType } from '../../gfx/define'; import { GFXUniformBlock, GFXUniformSampler } from '../../gfx/shader'; +import { UBOBinding as UBOBindings } from '../../pipeline/cc-binding'; export class SkinningUBO { public static MAT_JOINT_OFFSET: number = 0; @@ -8,13 +9,13 @@ export class SkinningUBO { public static SIZE: number = SkinningUBO.COUNT * 4; public static BLOCK: GFXUniformBlock = { - binding: 28, name: 'CCSkinning', members: [ + binding: UBOBindings.CC_SKINNING, name: 'CCSkinning', members: [ { name: 'cc_matJoint', type: GFXType.MAT4, count: 128 }, { name: 'cc_jointsTextureSize', type: GFXType.FLOAT4, count: 1 }, ], }; public static JOINT_TEXTURE: GFXUniformSampler = { - binding: 27, name: 'cc_jointsTexture', type: GFXType.SAMPLER2D, count: 1, + binding: UBOBindings.CC_JOINTS_TEXTURE, name: 'cc_jointsTexture', type: GFXType.SAMPLER2D, count: 1, }; } diff --git a/cocos/renderer/models/skinning-model.ts b/cocos/renderer/models/skinning-model.ts index 42a039ff57..7872cd6426 100644 --- a/cocos/renderer/models/skinning-model.ts +++ b/cocos/renderer/models/skinning-model.ts @@ -2,6 +2,7 @@ import Skeleton from '../../3d/assets/skeleton'; import { Texture2D } from '../../assets/texture-2d'; +import { Filter, PixelFormat, WrapMode } from '../../assets/texture-base'; import { mat4 } from '../../core/vmath'; import { GFXBuffer } from '../../gfx/buffer'; import { GFXBufferUsageBit, GFXMemoryUsageBit } from '../../gfx/define'; @@ -11,7 +12,6 @@ import { Node } from '../../scene-graph/node'; import { Model } from '../scene/model'; import { RenderScene } from '../scene/render-scene'; import { SkinningUBO } from './model-uniforms'; -import { PixelFormat, Filter, WrapMode } from '../../assets/texture-base'; const textureSizeBuffer = new Float32Array(4); @@ -159,4 +159,4 @@ function _createJointsTexture (skinning: { joints: any[]; }) { texture.setFilters(Filter.NEAREST, Filter.NEAREST); texture.setWrapMode(WrapMode.CLAMP_TO_EDGE, WrapMode.CLAMP_TO_EDGE); return texture; -} \ No newline at end of file +}